<?php
namespace app\admin\controller;

class Users extends \app\common\controller\Base {
	protected $modelname='AdminUser';
	protected $_AllowRecache=true;

	public function _index(){
		$condition=[];
		$param=$this->param;

		if (isset($param['user_name']))
			$condition[]=['user_name','like','%'.$param['user_name'].'%'];

		if (isset($param['email']))
			$condition[]=['email', 'like','%'.$param['email'].'%'];

		if (isset($param['real_name']))
			$condition[]=['real_name', 'like','%'.$param['real_name'].'%'];

		$userInfo=$GLOBALS['userInfo'];
		$gids = $userInfo['gids'];

		if (in_array(0,$gids)) {
			$condition[]=['id','not in',db('admin_access')->where("group_id",0)->distinct(true)->column('user_id')];
		} else {
			$userModel=model("AdminUser");
			$uids = $userModel->getAllChild([$userInfo['uid']]);
			if (count($uids))
				$condition[]=['id','in',uids];
			else
				$condition[]=['id', '=', 0];
		}

		return $condition;
	}

	protected function recache() {
		\think\facade\Cache::clear('USER_MENU');

	}
}

?>